<template>
  <div>
    <el-select v-model="centerId" clearable placeholder="请选择工作中心" filterable>
      <el-option v-for="center in centerOptions"
                 :key="center.id" :label="center.name" :value="center.id"/>
    </el-select>
  </div>
</template>

<script>
import { getCenterSimple } from "@/api/base/center"
export default {
  name: "SelectCenter",
  props: {
    value: {
      required: true
    }    
  },
  data() {
    return {
      centerOptions: [],
      centerId: this.value,
    }
  },
  watch: {
    value(newVal) {
      this.centerId = newVal;
    },
    centerId(newVal, oldVal){
      this.$emit("input", this.centerId)
    }
  },
  created() {
    this.getCenterListFun();
  },
  methods: {
    /** 查询工厂列表 */
    getCenterListFun(){
      getCenterSimple().then(response => {
        this.centerOptions = response.data;
      })
    },
  }
};
</script>

